// pages/syudy/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    levelList: [],
    lanList: [],
    defaultLan: 'java',
    defaultLevel: '初级',
    current: 1,
    size: 10,
    list: [],
    active: 0,
    levelRadio: '初级',
    lanRadio: 'java',
    levelIcon:'/pages/static/icon/初级标签.png',
    icon: {
      normal: '/pages/static/icon/选中.png',
      active: '/pages/static/icon/选中2.png',
    },
  },
  
  onChange1(event) {
    console.log(event.detail)
    let iconName = '';
    if(event.detail == '初级'){
      iconName='/pages/static/icon/初级标签.png';
    }else if(event.detail == '中级'){
      iconName='/pages/static/icon/中级标签.png';
    }else{
      iconName='/pages/static/icon/高级标签.png';
    }
    this.setData({
      levelRadio: event.detail,
      levelIcon:iconName
    });
    //刷新试卷
    this.getList();
  },
  onChange2(event) {
    this.setData({
      lanRadio: event.detail,
    });
    //刷新试卷
    this.getList();
  },
  //获取类别
  getType() {
    wx.http.get(getApp().globalData.getIndexItem + "/paper_type").then(res => {
      console.log(res)
      if (res.code == 200) {
        console.log(res)
        this.setData({
          lanList: res.data
        })
      }
    })
  },
  //获取级别
  getLevel() {
    wx.http.get(getApp().globalData.getIndexItem + "/paper_level").then(res => {
      let level = [];
      res.data.forEach(function (value, index) {
        let type = {};
        type.text = value.dictLabel;
        type.value = value.dictLabel
        level.push(type);
      })
      this.setData({
        level: level,
        defaultLevel: level[0].value
      });

    })
  },
  //获取列表
  getList() {
    wx.http.post(getApp().globalData.getExamPaperList, JSON.stringify({
      examPaperType: this.data.value1,
      examPaperLevel: this.data.value2,
      current: this.data.current,
      size: this.data.size,
      examPaperLevel: this.data.levelRadio,
      examPaperType: this.data.lanRadio
    })).then(res => {
      this.setData({
        list: res.data.records
      })
    })

  },
  //去考试
  gotoPapge(e) {
    wx.setStorageSync('examPaperId', e.currentTarget.dataset.id);
    wx.setStorageSync('answered', '')
    wx.navigateTo({
      url: '/packageB/pages/syudy/scanAnswer/index',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getLevel();
    this.getType();
    this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

})